package hdservice;

import com.ht.log.HisDBBackup;
import devmodel.MapObject;
import org.apache.log4j.Logger;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date:2011-09-14
 */
public class RemoteHdFacade extends UnicastRemoteObject implements HdFacade {
    private static Logger log = Logger.getLogger(RemoteHdFacade.class);

    RtHisDataLoader loader = new RtHisDataLoader();
    StatisticsAnalyzer statisticsAnalyzer;
    FesPointsChecker fesPointsChecker;

    public RemoteHdFacade() throws RemoteException {
        super();
    }

    public void initial() {
        loader.loadCmdRelatedRtu();
    }

    public void backupLog() throws RemoteException {
        HisDBBackup.backup();
    }

    public void loadPlan() {
        loader.loadPlan();
    }

    public void loadCmd() {
        loader.loadCmd();
    }

    public void loadMeasure() {
        loader.loadMeasure();
    }

    public void doStatisticAnalysis() {
        if (statisticsAnalyzer != null)
            statisticsAnalyzer.doStatisticAnalysis();
    }

    public void redoMonthStatisticAnalysis(Long time) {
        if (statisticsAnalyzer != null)
            statisticsAnalyzer.redoMonthStatisticAnalysis(time);
    }

    public void checkFesPoint() throws RemoteException {
        if (fesPointsChecker != null)
            fesPointsChecker.checkPoints();
    }

    public void checkPlan() throws RemoteException {
        PlanReminder reminder = new PlanReminder();
        try {
            reminder.remind();
        } catch (Exception e) {
            e.printStackTrace();
            log.warn(e);
        }
    }

    public void checkFesPointByDev(MapObject dev) throws RemoteException {
        if (dev.getId().equals("SMEPC1Station177_2"))
            return;
        if (fesPointsChecker != null)
            fesPointsChecker.checkPoints(dev);
    }

    public void deleteFesPoint(MapObject dev) throws RemoteException {
        if (fesPointsChecker != null)
            fesPointsChecker.deletePoints(dev);
    }

    public void setStatisticsAnalyzer(StatisticsAnalyzer statisticsAnalyzer) {
        this.statisticsAnalyzer = statisticsAnalyzer;
    }

    public void setFesPointsChecker(FesPointsChecker fesPointsChecker) {
        this.fesPointsChecker = fesPointsChecker;
    }
}
